#include <cstdio>

int main(int argc, char const* argv[])
{
    int turkeys;
    while (scanf("%d", &turkeys) != EOF) {
        bool exist_flag = false;
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        for (int i = 9; i > 0; i--) {
            for (int j = 9; j >= 0; j--) {
                int dollers = i * 10000 + x * 1000 + y * 100 + z * 10 + j;
                if (dollers % turkeys == 0) {
                    printf("%d %d %d", i, j, dollers / turkeys);
                    exist_flag = true;
                    break;
                }
            }
            if (exist_flag)
                break;
        }
        if (!exist_flag) {
            printf("0");
        }
    }
    return 0;
}